//
//  UpMainTabController.m
//  LoveFreshBee
//
//  Created by 夏惠斌 on 16/8/1.
//  Copyright © 2016年 夏惠斌. All rights reserved.
//

#import "UpMainTabController.h"
#import "UpMainNavController.h"
#import "UPFreshController.h"
#import "UpShortCartController.h"
#import "UpOrderController.h"
#import "UpMineController.h"
#import "UpHomeController.h"
@interface UpMainTabController ()

@end

@implementation UpMainTabController

- (void)setTabVC:(UIViewController *)cotroller imageName:(NSString *)imageName title:(NSString *)title {
    
    UpMainNavController *navVC = [[UpMainNavController alloc]initWithRootViewController:cotroller];
    UIImage *normalImg = [UIImage imageNamed:imageName];
    navVC.tabBarItem.image = normalImg;
    //imageWithRenderingMode:渲染模式,可以阻止tab控制器把图片渲染成蓝色
    NSString *selectedImageName = [NSString stringWithFormat:@"%@_r",imageName];
//    UIImage *selectedImg = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *selectedImg = [UIImage imageNamed:selectedImageName];
    navVC.tabBarItem.selectedImage = selectedImg;
    navVC.tabBarItem.title = title;
    NSDictionary *dict = @{NSForegroundColorAttributeName:[UIColor colorWithRed:174/255.0 green:171/255.0 blue:171/255.0 alpha:1],NSFontAttributeName:[UIFont systemFontOfSize:12]};//174 171 171
    [navVC.tabBarItem setTitleTextAttributes:dict forState:UIControlStateNormal];
    [self addChildViewController:navVC];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //首页
    UpHomeController *home = [[UpHomeController alloc]init];
    [self setTabVC:home imageName:@"v2_home" title:@"首页"];
    //闪送超市
    UpOrderController *order = [[UpOrderController alloc]init];
    [self setTabVC:order imageName:@"v2_order" title:@"闪送超市"];
    //新鲜预定
    UpFreshController * freshVC = [[UpFreshController alloc]init];
    [self setTabVC:freshVC imageName:@"freshReservation" title:@"新鲜预定"];
    //购物车
    UpShortCartController *shortCart = [[UpShortCartController alloc]init];
    [self setTabVC:shortCart imageName:@"shopCart" title:@"购物车"];
    //我的
    UpMineController *mine = [[UpMineController alloc]init];
    [self setTabVC:mine imageName:@"v2_my" title:@"我的"];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
